/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */



/**
 *
 * @author CHUCHIZ
 */

import java.sql.*;
import java.sql.DriverManager;
import java.sql.SQLException;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JInternalFrame;
import java.awt.event.*;

public class Main extends JInternalFrame{
   // static int openFrameCount = 0;
    //static final int xOffset = 30, yOffset = 30;

    public Main() throws SQLException{
    //setSize(200,200);
    /*super("Document #" + (++openFrameCount),
              true, //resizable
              true, //closable
              true, //maximizable
              true);//iconifiable
*/

    TestDatabaseConnection();
    test_Q();
    }


public  void TestDatabaseConnection() throws SQLException {

    
           String url = "jdbc:oracle:thin:@//192.168.59.5:1521/CHUZ";
           String driver = "oracle.jdbc.driver.OracleDriver";

			String username = "system";
			String password = "123456";
			Connection conn = null;
			try {
				Class.forName(driver);
				conn = DriverManager.getConnection(url, username, password);
				// conn.setAutoCommit(false);
				System.out.println("Test Database Connection Success!");
				// createExample();
			} catch (ClassNotFoundException e) {
				showWarningMsgDialog(e.getMessage());
			} catch (SQLException e) {
				showWarningMsgDialog(e.getMessage());
			} catch (Exception e) {
				showWarningMsgDialog(e.getMessage());
				//e.printStackTrace();
			} finally {
				try {
					conn.close();
				} catch (Exception e) {
					//e.printStackTrace();
				}
			}
}

public void test_Q(){
    String url = "jdbc:oracle:thin:@//192.168.59.5:1521/CHUZ";
    String driver = "oracle.jdbc.driver.OracleDriver";

			String username = "system";
			String password = "123456";
			Connection conn = null;
                        Statement stmt = null;
			try {
				Class.forName(driver);
				conn = DriverManager.getConnection(url, username, password);
				// conn.setAutoCommit(false);
                                stmt = conn.createStatement();
                                ResultSet rset = stmt.executeQuery("select COLUMN_NAME,DATA_LENGTH,COLUMN_ID from USER_TAB_COLUMNS where TABLE_NAME ='HELP'");
                                //int n=4;
            
                                 while (rset.next())
                                {
                                    //while(n <= 3)
                                      //  {
                                             String a = rset.getString("COLUMN_NAME");
                                             String b = rset.getString("DATA_LENGTH");
                                             String c = rset.getString("COLUMN_ID");
                                             //System.out.println(a);
                                             //n++;
                                        //}
                                }
                                     stmt.close();



				// createExample();
			} catch (ClassNotFoundException e) {
				showWarningMsgDialog(e.getMessage());
			} catch (SQLException e) {
				showWarningMsgDialog(e.getMessage());
			} catch (Exception e) {
				showWarningMsgDialog(e.getMessage());
				//e.printStackTrace();
			} finally {
				try {
					conn.close();
				} catch (Exception e) {
					//e.printStackTrace();
				}
    }
}


private void showWarningMsgDialog(String msgDetail) {
		JOptionPane.showMessageDialog(this, msgDetail, "Message",
				JOptionPane.WARNING_MESSAGE);
	}

//public static void main(String[] args) throws SQLException{
  // new Main().setVisible(true);
  //}
}
